In [1]:
import csv
from distance import distance
In [2]:
with open("result_dat_20160707-174437.csv") as file:
parsed_content = [
(float(line[24]), float(line[25]))
for line in csv.reader(file)
]
In [3]:
distances = []
for position1, position2 in zip(parsed_content, parsed_content[1:]):
distances.append(distance(position1, position2))
In [4]:
sum(distances)
Out[4]:
In [5]:
from functools import reduce
import csv
from distance import distance
In [6]:
def reduce_func(dist_and_last_point, new_point):
dist, last_point = dist_and_last_point
dist += distance(last_point, new_point)
return dist, new_point
In [7]:
reduce_func(
dist_and_last_point=(30, (45.738865, 4.870639)),
new_point=(45.738865, 4.870641)
)
Out[7]:
In [8]:
def initialize(iterable):
yield (0, next(iterable))
yield from iterable
In [9]:
list(initialize(iter("abcd")))
Out[9]:
In [10]:
with open("result_dat_20160707-174437.csv") as file:
# Creating
generator = (
(float(line[24]), float(line[25]))
for line in csv.reader(file)
)
# print(list(generator))
print(reduce(reduce_func, initialize(generator))[0])
In [ ]: